<template>
  <div class="radioOptions">
    <el-dialog title="批量编辑选择项" :visible.sync="dialogVisible">
      <el-tabs :tab-position="'left'"  @tab-click="tabClick">
        <el-tab-pane v-for="(item,index) in tableData" :key="index" :label="item.label">
          <el-input type="textarea" :rows="8" placeholder="请输入内容" v-model="item.options"></el-input>
          <!-- <p v-for="(opt,index) in item.options" :key="index">{{opt.VAL}}</p> -->
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "radioOptions",
  data() {
    return {
      dialogVisible: false,
      currentIndex: 0,
      textarea: "",
      tableData: [
        {
          label: "性别",
          // options: [
          //   { VAL: "男", CHKED: "0" },
          //   { VAL: "女", CHKED: "1" }
          // ],
          options: "男\n女"
        },
        {
          label: "年龄",
          options: "18岁以下\n18-25岁\n25-35岁\n35-45岁\n45-60岁\n60岁以上"
        },
        {
          label: "工作情况",
          options: "全职\n兼职\n个体户\n已退休\n学生"
        },
        {
          label: "教育程度",
          options: "高中及以下\n大专\n本科\n硕士\n博士及以上"
        }
      ]
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
    },
    confirm() {
      let item = this.tableData[this.currentIndex];
      let list = item.options.split("\n");
      let arr = [];
      for (let i = 0; i < list.length; i++) {
        let str = list[i].trim();
        if (str) {
          arr.push({
            VAL: str,
            CHKED: "0"
          });
        }
      }
      let obj = {
        label: item.label,
        options: arr
      };
      this.$emit("selected", obj);
      this.dialogVisible = false;
    },
    tabClick(e) {
      this.currentIndex = e.index;
    }
  }
};
</script>
<style lang="scss" scoped>
.el-textarea{

}
</style>